package com.qf.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.qf.mapper.ShopMapper;
import com.qf.pojo.Shop;
import com.qf.service.ShopService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author Kuke
 * @date 2022/3/22 11:14
 * 针对商品的业务接口实现
 */

@Service
public class ShopServiceImpl implements ShopService {
@Autowired
   private ShopMapper shopMapper;
    @Override
    public List<Shop> findAll(Integer page, Integer size) {
        //设置分页
        PageHelper.startPage(page,size);
        //查询
        List<Shop> list = shopMapper.findAllShop();
        //设置分页实体的组件
        PageInfo<Shop> pageInfo = new PageInfo<>(list);
        return list;
    }

    @Override
    public void add(Shop shop) {
        System.out.println("添加商品执行了");
        shopMapper.addShop(shop);
    }

    @Override
    public void update(Shop shop) {
        System.out.println("修改商品成功了");
        shopMapper.updateShop(shop);
    }

    @Override
    public void delete(Shop shop) {
        System.out.println("删除商品成功了");
        shopMapper.deleteShop(shop);
    }

    @Override
    public void transfer(String transfername, String totransfername, Integer money) {
        shopMapper.addMoney(transfername,money);
        int i = 10/0;
        shopMapper.decreaseMoney(totransfername,money);
    }
}

